package com.zb.order.controller;


import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.zb.entity.AccounLoginInfo;
import com.zb.result.PageUtil;
import com.zb.result.Result;
import com.zb.service.ZjWorkTableFieldService;
import com.zb.utils.TokenUtil;
import com.zb.vo.WorkTableFieldVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.regex.Pattern;

/**
 * <p>
 * 工单列表表头字段表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2024-01-24
 */
@Api(tags = "工单列表表头设置类接口")
@RestController
@RequestMapping("/workTableField")
public class ZjWorkTableFieldController {
    @Resource
    private ZjWorkTableFieldService workTableFieldService;


    @ApiOperation("保存或更新工单表头字段")
    @PostMapping("/save/{type}")
    public Result save(HttpServletRequest request, @PathVariable @ApiParam(value = "表头类型：1-工单列表，2-存档列表，3-结算列表") Integer type, @RequestBody List<WorkTableFieldVo> tableFieldVos) {
        Assert.isTrue(Pattern.matches("^(1|2|3)$", type.toString()), "表头类型参数不合法");
        AccounLoginInfo loginInfo = TokenUtil.getAccountLoginInfo(request);
        workTableFieldService.save(loginInfo, type, tableFieldVos);
        return Result.success("表头字段保存成功");
    }

    @ApiOperation("获取工单表头初始化字段")
    @GetMapping("/getOrderTableInitField")
    public Result getOrderTableInitField() {
        return Result.success("获取工单表头初始化字段成功").data(PageUtil.rows(workTableFieldService.getOrderTableInitField()));
    }

    @ApiOperation("获取工单表头字段设置项")
    @GetMapping("/getOrderTableField/{type}")
    public Result getOrderTableField(HttpServletRequest request, @PathVariable @ApiParam(value = "表头类型：1-工单列表，2-存档列表，3-结算列表") Integer type) {
        Assert.isTrue(Pattern.matches("^(1|2|3)$", type.toString()), "表头类型参数不合法");
        AccounLoginInfo loginInfo = TokenUtil.getAccountLoginInfo(request);
        return Result.success().data(PageUtil.rows(workTableFieldService.getOrderTableField(loginInfo, type)));
    }

    @ApiOperation("获取工单列表表头字段")
    @GetMapping("/getOrderListTableField/{type}")
    public Result getOrderListTableField(HttpServletRequest request, @PathVariable @ApiParam(value = "表头类型：1-工单列表，2-存档列表，3-结算列表") Integer type) {
        Assert.isTrue(Pattern.matches("^(1|2|3)$", type.toString()), "表头类型参数不合法");
        AccounLoginInfo loginInfo = TokenUtil.getAccountLoginInfo(request);
        return Result.success().data(PageUtil.rows(workTableFieldService.getOrderListTableField(loginInfo, type)));
    }



}
